import { isObj } from '../core/isObj'
import { isFn } from '../core/isFn'
import { isArr } from '../core/isArr'
import { mapObj } from '../core/mapObj'
// 19546
/**
 * 深复制
 * example
         * const obj = [{ a: 1 }, { a: 2 }];
         * const obj2 = cloneDeep(obj);
         * console.log(obj[0] === obj2[0]); // -> false
         * 
  dependencies isObj isFn isArr mapObj
 * @param val 
 */
export function cloneDeep (obj) {
  if (isArr(obj)) {
    return obj.map(function (val) {
      return cloneDeep(val);
    });
  }

  if (isObj(obj) && !isFn(obj)) {
    return mapObj(obj, function (val) {
      return cloneDeep(val);
    });
  }

  return obj;
}